package com.bioroadlab.interceptor;

import java.util.Map;
import java.util.Set;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.TextParseUtil;

@SuppressWarnings("static-access")
public class CheckLoginInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 1L;
	private String exclude;
	private String sysuser;

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		Set<String> set = TextParseUtil.commaDelimitedStringToSet(exclude);
		if (set.contains(actionInvocation.getProxy().getActionName())) {
			return actionInvocation.invoke();
		} else {
			Map<String, Object> session = actionInvocation
					.getInvocationContext().getContext().getSession();
			if ((!session.isEmpty()) && (session.get(sysuser) != null)) {
				return actionInvocation.invoke();
			}
		}
		return "loginFail";
	}

	public String getExclude() {
		return exclude;
	}

	public void setExclude(String exclude) {
		this.exclude = exclude;
	}

	public String getSysuser() {
		return sysuser;
	}

	public void setSysuser(String sysuser) {
		this.sysuser = sysuser;
	}
}
